package com.dsbj.it.DingTalkBotStarter.util;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.ArrayList;
import java.util.List;

public class ExcelUtils {

    public static List<List<Object>> getAllColumns(String filePath) {
        List<List<Object>> allColumns = new ArrayList<>();
        AnalysisEventListener<List<Object>> listener = new AnalysisEventListener<List<Object>>() {
            @Override
            public void invoke(List<Object> rowData, com.alibaba.excel.context.AnalysisContext context) {
                allColumns.add(rowData);
            }

            @Override
            public void doAfterAllAnalysed(com.alibaba.excel.context.AnalysisContext context) {
                // 文件解析完成后的操作
            }
        };
        EasyExcel.read(filePath).registerReadListener(listener).sheet().doRead();
        return allColumns;
    }

    public static void main(String[] args) {
        String filePath = "D:\\0project\\DingTalkBot\\demo\\file\\input.xlsx";
        List<List<Object>> allColumns = getAllColumns(filePath);
        for (List<Object> column : allColumns) {
            System.out.println(column);
        }
    }
}